<template>
	<view class="content padding">
		<view v-for="(item,index) in coupon.coupons" :key="index" class="activity_coupon">
			<view class="activity_coupon_top">
				<view class="activity_coupon_top_view">
					<view class="activity_coupon_font_view">
						<view class="amount">
							<view class="amount_rmb">￥</view>
							<view class="amonut_price">{{item.amount}}</view>
						</view>
						<view style="flex-direction: column;margin-left: 30upx;">
							<view style="color: #fa491e;font-size: 24upx;">{{item.amountCondition}} </view>
							<view style="color: #fa491e;font-size: 24upx;">{{item.explain}} </view>
						</view>
					</view>
					<view style="width: 200upx;justify-content: center;">
						<view class="obtain_bt" v-if="item.status==0" @tap="obtain(item.id)">领取</view>
						<view class="obtain_bt_" v-if="item.status==1" @tap="goActivity(item.activityId)">使用</view>
					</view>
				</view>
			</view>
			<view class="activity_coupon_bottom">
				<view class="left_dto"></view>
				<view class="right_dto"></view>
				<view v-for="product in item.products" :key="product.id" class="activity_product_view" @tap="goPorduct(product.id)">
					<image :src="product.mainImage" style="width: 200upx;height: 200upx;" mode="aspectFill" lazy-load></image>
					<view style="width: 100%;color: #333333;margin-top: 15upx;" class="text_one"> {{product.name}}</view>
					<view style="color: #333333;align-items: flex-end;margin-top: 10upx;line-height: 1;">
						<view>￥</view>
						<view style="font-size: 35upx;font-weight: 700;line-height: 25upx;">{{product.price}}</view>
						<view style="margin-left: 10upx;color: #fa491e;background-color: #fff1ed;">可用券</view>
					</view>
				</view>
			</view>
			<view class="obatin" v-if="item.status==1">已领取</view>
		</view>
		<view style="margin-top: 30upx;flex-wrap: wrap;">
			<view v-for="(item,index) in coupon.productCoupon" :key="index" :class="[index%2==0?'product_left':'product_right']">
				<view class="obatin" v-if="item.status==1">已领取</view>
				<view class="product_coupon_view">
					<view style="flex-direction: column;">
						<view style="align-items: flex-end;color: #fa491e;">
							<view style="font-size: 40upx;line-height: 1;">￥</view>
							<view style="font-size: 70upx;font-weight: 600;line-height: 1;">{{item.amount}}</view>
						</view>
						<view style="color: #fa491e;font-size: 24upx;">{{item.amountCondition}}</view>
					</view>
					<view>
						<view class="obtain_bt" v-if="item.status==0" @tap="obtain(item.id)">领取</view>
						<view class="obtain_bt_" v-if="item.status==1" @tap="goPorduct(item.id)">使用</view>
					</view>
				</view>
				<view class="product_coupon_bottom" @tap="goPorduct(item.id)">
					<view class="left_dto"></view>
					<view class="right_dto"></view>
					<image :src="item.mainImage" style="width: 300upx;height: 300upx;" mode="aspectFill" lazy-load></image>
					<view class="text_one" style="color: #333333;width: 100%;margin-top: 15upx;">{{item.name}}</view>
					<view style="justify-content: space-between;align-items: flex-end;line-height: 1;">
						<view style="align-items: flex-end;margin-top: 10upx;line-height: 1;color: #333333;">
							<view style="margin-left: 10upx;color: #fa491e;background-color: #fff1ed;font-size: 24upx;line-height: 1;">券后价</view>
							<view style="line-height: 1;">￥</view>
							<view style="font-size: 35upx;font-weight: 700;line-height: 25upx;">{{item.realPrice}}</view>
						</view>
						<view style="color: #888888;text-decoration: line-through;line-height: 1;">￥{{item.price}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../common/api.js';
	import {
		get_,
		getWithParam_
	} from '../../common/request.js';
	export default {
		data() {
			return {
				coupon: {}
			}
		},
		onLoad() {
			this.initData()
		},

		methods: {
			goActivity(id) {
				if (id == null || id == '') {
					uni.navigateTo({
						url: "../product/list"
					})
				} else {
					uni.navigateTo({
						url: "../activity/index?id=" + id
					})

				}
			},
			goPorduct(id) {
				uni.navigateTo({
					url: "../product/detail?id=" + id
				})
			},
			obtain(id) {
				getWithParam_(api.COUPON_OBTAIN, {
					id
				}).then(res => {
					this.initData()
				})
			},
			initData() {
				get_(api.COUPON_LIST).then(res => {
					this.coupon = res.data
				})
			}

		}
	}
</script>

<style>
	.obatin {
		font-size: 22upx;
		background-color: #07C160;
		color: #FFFFFF;
		height: 40upx;
		width: 200upx;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 5upx;
		left: -70upx;
		transform: rotate(-45deg);
	}

	.amonut_price {
		font-size: 70upx;
		font-weight: 600;
		line-height: 1;
	}

	.amount_rmb {
		font-size: 40upx;
		line-height: 1;
	}

	.amount {
		align-items: flex-end;
		color: #fa491e;
	}

	.product_coupon_bottom {
		padding: 20upx;
		box-sizing: border-box;
		background-color: #FFFFFF;
		flex-direction: column;
		position: relative;
	}

	.product_coupon_view {
		background-color: #fff1ed;
		padding: 20upx;
		box-sizing: border-box;
		align-items: center;
		justify-content: space-between;
	}

	.activity_product_view {
		padding-top: 20upx;
		width: 33.3%;
		flex-direction: column;
		padding: 15upx;
		box-sizing: border-box;
	}

	.right_dto {
		position: absolute;
		right: -20upx;
		top: -20upx;
		border-radius: 40upx;
		height: 40upx;
		width: 40upx;
		background-color: #F8F8F8;
	}

	.left_dto {
		position: absolute;
		left: -20upx;
		top: -20upx;
		border-radius: 40upx;
		height: 40upx;
		width: 40upx;
		background-color: #F8F8F8;
	}

	.activity_coupon_bottom {
		background-color: #FFFFFF;
		border-bottom-left-radius: 20upx;
		border-bottom-right-radius: 20upx;
		position: relative;
	}

	.obtain_bt {
		border: 3upx solid #f95706;
		background-color: #f95706;
		padding: 5upx 30upx;
		border-radius: 50upx;
		color: #FFFFFF;
		font-size: 24upx;
	}

	.obtain_bt_ {
		border: 3upx solid #f95706;
		padding: 5upx 30upx;
		border-radius: 50upx;
		color: #f95706;
		font-size: 24upx;
	}

	.activity_coupon_font_view {
		flex: 1;
		align-items: center;
		justify-content: center;
	}

	.activity_coupon_top_view {
		justify-content: space-between;
		width: 100%;
		height: 150upx;
		align-items: center;
	}

	.activity_coupon_top {
		background-color: #fff1ed;
		border-top-left-radius: 20upx;
		border-top-right-radius: 20upx;
	}

	.activity_coupon {
		border-radius: 20upx;
		overflow: hidden;
		flex-direction: column;
		position: relative;
		margin-top: 30upx;
	}

	.product_left {
		margin-top: 30upx;
		border-radius: 20upx;
		flex-direction: column;
		width: 330upx;
		position: relative;
		overflow: hidden;
	}

	.product_right {
		margin-top: 30upx;
		margin-left: 30upx;
		border-radius: 20upx;
		flex-direction: column;
		width: 330upx;
		position: relative;
		overflow: hidden;
	}
</style>
